package com.example.music.controller;


import com.example.music.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.example.music.utils.FileHandle;
@RestController
@RequestMapping("/musicoss/fileoss")
@CrossOrigin
public class OssController {
    @Autowired
    private OssService ossService;

    //上传音乐方法
    @PostMapping
    public String uploadOssFile(MultipartFile file){
        //获取上传文件 MultipartFile

        String fileName = file.getOriginalFilename();
        FileHandle fileHandle=new FileHandle();
        System.out.println(fileHandle.getSingger(fileName));
        System.out.println(fileHandle.getTitle(fileName));

//        System.out.println("文件名 "+fileName);
//
//        String singer=fileName.substring(0,fileName.indexOf("-"));
//        System.out.println("歌手 "+singer);
//        String title=fileName.substring(fileName.indexOf("-")+1,fileName.lastIndexOf("."));
//
//        System.out.println("歌曲名 "+title);

        //返回上传到oss的路径

        String url=ossService.uploadFileMusic(file);

        return url;
    }

}
